package xyz.masaikk;

import java.util.Arrays;
class GenerateP{

    private int count;
    private int n;
    private final int maxnum = 110;
    private boolean [] flags;
    private int [] p;

    public GenerateP(int n) {
        this.n = n;
        flags = new boolean[maxnum];
        p = new int [maxnum];
        Arrays.fill(flags, false);
        Arrays.fill(p, 0);
        count = 0;
    }
    public void generatep(int index){
        if(index == n + 1){
            boolean flag = true;
            for(int i = 1; i <= n ;i++){
                for(int j = i + 1; j <= n ;j++){
                    if(Math.abs(i - j) == Math.abs(p[i] - p[j])){
                        flag = false;
                        break;
                    }
                }
            }
            if(flag==true){
                count++;
            };
            return;
        };
        for(int x = 1; x <= n; x++){
            if(flags[x] == false){
                p[index] = x;
                flags[x] = true;
                generatep(index + 1);
                flags[x] = false;
            }
        }
    }
    public int getCount(){
        System.out.println(this.count);
        return this.count;
    }


}

